/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * Project Name: lmrp-android app
 * Create Time: 16-2-16 下午6:42
 */

package com.lenovo.mso2o.ui.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lenovo.framework.util.DLog;
import com.lenovo.mso2o.R;
import com.lenovo.mso2o.conf.MSConstants;
import com.lenovo.mso2o.ui.fragment.HistoryOrderFragment;
import com.lenovo.mso2o.ui.fragment.IndexFragment;
import com.lenovo.mso2o.ui.fragment.NotificationFragment;
import com.lenovo.mso2o.ui.fragment.OrderFilterFragment;


/**
 * Created by hippo on 10/29/15.
 */
public class MainTabPagerAdapter extends FragmentPagerAdapter{

    public static String mTextviewArray[] = {"首页", "活动工单", "历史工单", "消息"};
    private int mImageViewArray[] = {R.drawable.home_normal,R.drawable.activeorder_normal,R.drawable.historyorder_normal, R.drawable.message_normal};
    private int mImageViewArraySelected[] = {R.drawable.home_pressed,R.drawable.activeorder_pressed,R.drawable.historyorder_pressed, R.drawable.message_pressed};
    private IndexFragment mainFragment;
    private OrderFilterFragment activeFragment;
    private HistoryOrderFragment historyFragment;
    private NotificationFragment messageFragment;

    public MainTabPagerAdapter(FragmentManager fragmentManager, Context context){
        super(fragmentManager);
        mainFragment = IndexFragment.newInstance();
        activeFragment = OrderFilterFragment.newInstance(context, MSConstants.FragmentType.FRAGMENT_ACTIVORDERS);
        historyFragment = new HistoryOrderFragment();
        messageFragment = (NotificationFragment) NotificationFragment.newInstance();
    }
    @Override
    public int getCount() {
        return mTextviewArray.length;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position){
            case 0:
                return mainFragment;
            case 1:
                return activeFragment;
            case 2:
                return historyFragment;
            case 3:
                return messageFragment;

        }
        //should not happen!!!
        DLog.a(false);
        return null;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTextviewArray[position];
    }

    public int getPageIcon(int position, boolean selected) {
        return selected ? mImageViewArraySelected[position] : mImageViewArray[position];
    }

    public String getFragmentTag(int viewPagerId, int fragmentPosition) {
        return "android:switcher:" + viewPagerId + ":" + fragmentPosition;
    }

}
